
<template>
    <div class="model-form">
        <el-page-header @back="goBack" content="更新店铺运费券">
        </el-page-header>
        <div class="model-content">
            <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px" >
                <el-row :gutter="10">
 <el-col :span="20">
     <el-form-item label="名称" size="mini" prop="name">
             <el-input v-model="form.name" name="name">
             </el-input>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="封面" size="mini" prop="logo">
             <avatar  v-model="form.logo"  ></avatar>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="面额" size="mini" prop="money">
             <el-input v-model="form.money" name="money">
             </el-input>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="商家" size="mini" prop="shop">
             <el-select style="width: 100%;"  v-model="form.shop" filterable clearable
                     placeholder="请选择">
                 <el-option v-for="item in shopOptions" :key="item.id"
                         :label="item.name" :value="item.id">
                 </el-option>
             </el-select>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="使用门槛" size="mini" prop="minPrice">
              <el-input  v-model.number="form.minPrice" name="minPrice">
              </el-input>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="每人限领" size="mini" prop="limitNum">
            <el-input-number v-model="form.limitNum" name="limitNum" type="textarea" :min="0" :max="100"></el-input-number>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="发放开始时间" size="mini" prop="sendBeginTime">
             <el-date-picker v-model="form.sendBeginTime" type="datetime" value-format="yyyy-MM-dd HH:mm" placeholder="选择日期">
             </el-date-picker>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="发放截止时间" size="mini" prop="sendEndTime">
             <el-date-picker v-model="form.sendEndTime" type="datetime" value-format="yyyy-MM-dd HH:mm" placeholder="选择日期">
             </el-date-picker>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="有效期" size="mini" prop="expireType">
             <el-radio v-model="form.expireType" label="1">备选项</el-radio>
             <el-radio v-model="form.expireType" label="2">备选项</el-radio>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="优惠券开始时间" size="mini" prop="useBeginTime">
             <el-date-picker v-model="form.useBeginTime" type="datetime" value-format="yyyy-MM-dd HH:mm" placeholder="选择日期">
             </el-date-picker>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="优惠券截止时间" size="mini" prop="useEndTime">
             <el-date-picker v-model="form.useEndTime" type="datetime" value-format="yyyy-MM-dd HH:mm" placeholder="选择日期">
             </el-date-picker>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="固定天数" size="mini" prop="useDay">
            <el-input-number v-model="form.useDay" name="useDay" type="textarea" :min="0" :max="100"></el-input-number>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="卡券库存" size="mini" prop="stock">
            <el-input-number v-model="form.stock" name="stock" type="textarea" :min="0" :max="100"></el-input-number>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="使用说明" size="mini" prop="note">
             <el-input v-model="form.note" name="note" type="textarea"></el-input>
     </el-form-item>
      
 </el-col>
 <el-col :span="20">
     <el-form-item label="活动范围" size="mini" prop="couponScope">
             <el-input v-model="form.couponScope" name="couponScope">
             </el-input>
     </el-form-item>
      
 </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24"  style="text-align: right;padding-bottom: 20px;padding-top: 20px;">
                        <el-button @click="goBack">取消</el-button>
                        <el-button type="primary" @click="updateData">确定</el-button>
                    </el-col>
			     </el-row>
            </el-form>
        </div>
    </div>
</template>

<script>
import common from "@/mixins/common.js";

export default {
  name: "dishgroup_add",
  mixins: [common],
  data() {
    return {
        form: {
                name: '',
                logo: '',
                money: '',
                shop: '',
                minPrice: '',
                limitNum: '',
                sendBeginTime: '',
                sendEndTime: '',
                expireType: '',
                useBeginTime: '',
                useEndTime: '',
                useDay: '',
                stock: '',
                note: '',
                couponScope: ''            },
            rules: {
                    name: [
                        { required: true, message: '请输入名称', trigger: 'blur' }
                    ],
                    shop: [
                        { required: true, message: '请输入商家', trigger: 'blur' }
                    ],
        }
    };
  },
  methods: {
    updateData() {
      var self = this;
      this.$refs["ruleForm"].validate(function (valid) {
        if (valid) {
          self.updateDataWork();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    updateDataWork() {
      var self = this,
        data = this.form;
      if (this.deforeAddData) {
        this.deforeAddData();
      }
      this.postData("/tenantRest/freightcouponrule/create.htm", data, function () {
        self.$message({
          message: "更新数据成功",
          type: "success",
        });
        self.$router.go(-1);
      });
    },
  },
  mounted() {
    this.getShopList();

    var id = this.$route.query.id;
    var self = this;
    var data = {};
    data.id = id;

    this.$HTTP.form("/tenantRest/freightcouponrule/view.htm", data).then((res) => {
      if (res.code == 0) {
        self.form = res;
      }
    });
  },
};
</script>

<style>
</style>